<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>移动日志列表</title>
<%@include file="/common/head.jsp" %>
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/WdatePicker.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>移动日志管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">请求参数</span>
         <input type="text" class="summer-input" id="requestParam"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">返回值</span>
        <input type="text" class="summer-input" id="responseData"/>
    </span>
    
 	<span class="field-cont">
        <span class="field-cont-title">开始时间</span>
        <input type="text" class="summer-input" id="startTime" onFocus="var afterTime=$dp.$('endTime');WdatePicker({dateFmt:'yyyy-MM-dd',onpicked:function(){afterTime.focus();},maxDate:'#F{$dp.$D(\'endTime\')}'})"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">结束时间</span>
        <input type="text" class="summer-input" id="endTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime\')}'})"/>
    </span>
   
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>时间</th>
                <th>登录名</th>
                <th>请求参数</th>
                <th>返回值</th>
                <th>请求状态</th>
                <th>URI</th>
                <th>IP</th>
                <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
    var permission = CommonUtil.getPermission('mobilelog');
    
    $(function () {
        //初始化表格
        createTable();
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function() {
            //重置文本框的值
            $('#requestParam').val('');
            $('#startTime').val('');
            $('#endTime').val('');
            //$('#resourceName').val('');
            $('#responseData').val('');
            
            reloadTable();
        });
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="mobilelog:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = LOG_CONST_URL.INIT_VIEW +"?id=" + id;
        });
        
        //
        $('#t-wrap').on('click', 'a[data-permit="mobilelog:initViewError"]', function() {
        	var $this = $(this),
        	    id = $this.html();
        	window.location.href = LOG_CONST_URL.INIT_VIEW_ERROR +"?id=" + id;
        });
        
       //删除
       $('#t-wrap').on('click', 'a[data-permit="mobilelog:delete"]', function () {
    	   var $this = $(this),
    	       id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
    	   $.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : LOG_CONST_URL.DEL + "?ids=" + id,
			                onLoadSuccess : function() {
			                	$.stip({
	               	                type:'ok',//显示类型 有info、 ok、 danger
	               	                text: '删除成功！'
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
       });
        
        
    });
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
    				//"resourceName": trimSpace($('#resourceName').val()),
                    "requestParam": trimSpace($('#requestParam').val()),
                    "responseData": trimSpace($('#responseData').val()),
                    "startTime": $('#startTime').val(),
                    "endTime": $('#endTime').val()
    			}
            }
        });
	}
    

    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: LOG_CONST_URL.LIST,
    			param: {
    				//"resourceName": trimSpace($('#resourceName').val()),
                    "requestParam": trimSpace($('#requestParam').val()),
                    "responseData": trimSpace($('#responseData').val()),
                    "startTime": $('#startTime').val(),
                    "endTime": $('#endTime').val()
    			}
    		},
    		columns: [
    		      {
    		    	  field: 'id',
    		    	  hidden: true
    		      },
    		      {
    		    	  field: 'createTime',
    		    	  render: function (rowData) {
    		    		 return '<a href="javascript:;" data-permit="mobilelog:initView" class="link">'+ rowData.createTime +'</a>';
    		    	  }
    		      },
    		      {
    		    	  field: 'userName'
    		      },
    		      {
    		    	  field: 'requestParam'
    		      },
    		      {
    		    	field: 'responseData'
    		      },
    		      {
    		    	  field: 'status'
    		      },
    		      {
    		    	  field: 'url'
    		      },
    		      {
    		    	  field: 'ip'
    		      },
    		      {
                      render: function (rowData) { 
                           return  $.funcbar({
                              data: permission,    //请求的数据
                              type:'text',    //类型
                              permit: ['mobilelog:delete'] //需要的权限按钮
                          });
                      }
                  }
    		]
    	});
    }
    
    function isContains(str, substr) {
        return str.indexOf(substr) >= 0;
    }
    
    //请求url
    var LOG_CONST_URL = {
        LIST: basePath + '/sys/mobilelog/list',
        INIT_VIEW: basePath + '/sys/mobilelog/initView',
        INIT_VIEW_ERROR: basePath + '/sys/mobilelog/initViewError',
        DEL: basePath + "/sys/mobilelog/delete"
    };
    
</script>
</body>
</html>